package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/alert-rule")
@RestController
@Api(tags = "报警规则管理相关接口")
public class AlertRuleController extends BaseController{

    @Autowired
    private AlertRuleService alertRuleService;


    @PostMapping("/create")
    @ApiOperation(value = "创建报警规则")
    public ResponseResult create(@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.create(alertRuleDto);
        return success();
    }

    @GetMapping("/get-page")
    @ApiOperation(value = "分页查询报警规则")
    public ResponseResult getPage(Integer pageNum, Integer pageSize,
                                  String alertRuleName,String functionName,
                                  String productKey) {
        PageResponse<AlertRuleVo> pageResponse = alertRuleService.getPage(pageNum, pageSize, alertRuleName, functionName, productKey);
        return success(pageResponse);
    }

    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据id查询报警规则")
    public ResponseResult readById(@PathVariable Long id) {
        AlertRuleVo alertRuleVo =alertRuleService.readById(id);
        return success(alertRuleVo);
    }

    @PutMapping("/update/{id}")
    @ApiOperation(value = "更新报警规则")
    public ResponseResult updateById(@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.updateById(alertRuleDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除报警规则")
    public ResponseResult deleteById(@PathVariable Long id) {
        alertRuleService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "更新报警规则状态")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        alertRuleService.updateStatus(id,status);
        return success();
    }
}
